<template>
	<div>
		<el-dialog
				title="修改新闻"
				@close="clear">
			<el-form :model="form" style="text-align: left;width:70%" ref="form">
				
				<el-form-item label="新闻标题" :label-width="formLabelWidth" prop="title">
					<el-input v-model="form.title" autocomplete="off" placeholder=""></el-input>
				</el-form-item>
				<el-form-item label="作者/来源" :label-width="formLabelWidth" prop="author">
					<el-input v-model="form.author" autocomplete="off"></el-input>
				</el-form-item>
				<el-form-item label="发布日期" :label-width="formLabelWidth" prop="date">
					<el-col :span="11">
						<el-date-picker type="date" placeholder="选择日期" v-model="form.date"
										style="width: 100%;"></el-date-picker>
					</el-col>
					<el-col class="line" :span="1">—</el-col>
					<el-col :span="11">
						<el-time-picker placeholder="选择时间" v-model="form.date" style="width: 100%;"></el-time-picker>
					</el-col>
				</el-form-item>
				<el-form-item label="新闻链接" :label-width="formLabelWidth" prop="url">
					<el-input v-model="form.url" autocomplete="off"></el-input>
				</el-form-item>
				<el-form-item label="简介" :label-width="formLabelWidth" prop="abs">
					<el-input type="textarea" v-model="form.abs" autocomplete="off"></el-input>
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click="dialogFormVisible = false">取 消</el-button>
				<el-button type="primary" @click="submitForm('form')">修改</el-button>
			</div>
		</el-dialog>
	</div>
</template>

<script>
    export default {
        name: 'UpdateForm',
        data () {
            return {
                dialogFormVisible: false,
                form: {
                    id: '',
                    title: '',
                    author: '',
                    date: '',
                    url: '',
                    // cover: '',
                    abs: '',
                },
                formLabelWidth: '120px'
            }
        },
        methods: {
            clear () {
                this.form = {
                    id: '',
                    title: '',
                    author: '',
                    date: '',
                    url: '',
                    // cover: '',
                    abs: ''
                }
            },
            submitForm(formName) {
                const _this = this
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        _this.$http
                            .put('/news/update', this.form).then(function (resp) {
                            if (resp.data == 'success') {
                                _this.$alert('成功修改！标题:' + _this.form.title, '消息', {
                                    confirmButtonText: '确定',
                                    callback: action => {
                                        _this.$router.push('/data/news')
										//  this.dialogFormVisible = false
                                    }
                                })
                            }
                        })
                    } else {
                        return false;
                    }
                });
            }
        },
		created() {
            const _this = this
            this.$http.get('/news/findById/' +this.$route.query.id).then(function (resp) {
                _this.form = resp.data
            })
		}
    }
</script>

<style scoped>
</style>
